package com.zhou.piledriver.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhou.piledriver.aop.SuperValid;
import com.zhou.piledriver.common.PageRequest;
import com.zhou.piledriver.common.R;
import com.zhou.piledriver.common.ResponseResult;
import com.zhou.piledriver.model.entity.SysTenant;
import com.zhou.piledriver.model.so.SimpleSo;
import com.zhou.piledriver.service.SysTenantService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ZhouShenBin
 * @date 2024/3/14 14:11
 * @description
 */
@RestController
@RequestMapping("/tenant")
@Tag(name = "租户管理")
public class SysTenantController {
    @Resource
    private SysTenantService sysTenantService;

    @PostMapping("/page")
    @Operation(summary = "租户列表")
    @SuperValid
    public ResponseResult pageTenant(@RequestBody PageRequest<SimpleSo> so) {
        return R.success(sysTenantService.pageTenant(new Page<>(so.getCurrent(), so.getSize()), so.getQuery()));
    }

    @PostMapping("/create")
    @Operation(summary = "新增租户")
    @SuperValid
    public ResponseResult createTenant(@RequestBody SysTenant sysTenant) {
        return R.success(sysTenantService.createTenant(sysTenant));
    }

    @PostMapping("/edit")
    @Operation(summary = "修改租户")
    @SuperValid
    public ResponseResult editTenant(@RequestBody SysTenant sysTenant) {
        return R.success(sysTenantService.editTenant(sysTenant));
    }

    @PostMapping("/list")
    @Operation(summary = "租户列表")
    public ResponseResult listTenant() {
        return R.success(sysTenantService.listTenant());
    }
}
